﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Common;
using BusinessEntity.Common;
using BusinessEntity.FileManagement;
using BusinessAction.FileManagement;

 public class FileManagementService : UpdateSession, IFileManagementService
    {     

        #region ICommunicationService Members

     SortableCollection<MyFile> IFileManagementService.SearchFile(string sessionId, MyFile oMyFile, out string successMessage, out string errorMessage)
        {
            successMessage = string.Empty;
            errorMessage = string.Empty;
            try
            {
                // Update user session
                base.UpdateUserSession(sessionId);

                FileManager oFileManager = new FileManager();
                return oFileManager.SearchFile(sessionId, oMyFile, out successMessage, out errorMessage);

            }
            catch (Exception ex)
            {
                Utility.LogEmail(ex);
                errorMessage = Utility.GetExceptionMessageString(ex);
                return null;
            }
        }


     SortableCollection<MyFileType> IFileManagementService.GetFileType(string sessionId, out string successMessage, out string errorMessage)
     {
         successMessage = string.Empty;
         errorMessage = string.Empty;
         try
         {
             // Update user session
             base.UpdateUserSession(sessionId);

             FileManager oFileManager = new FileManager();
             return oFileManager.GetFileType(sessionId,out successMessage, out errorMessage);
             
         }
         catch (Exception ex)
         {
             Utility.LogEmail(ex);
             errorMessage = Utility.GetExceptionMessageString(ex);
             return null;
         }
     }


     SortableCollection<DocumentType> IFileManagementService.GetDocumentType(string sessionId, out string successMessage, out string errorMessage)
     {
         successMessage = string.Empty;
         errorMessage = string.Empty;
         try
         {
             // Update user session
             base.UpdateUserSession(sessionId);

             FileManager oFileManager = new FileManager();
             return oFileManager.GetDocumentType(sessionId, out successMessage, out errorMessage);

         }
         catch (Exception ex)
         {
             Utility.LogEmail(ex);
             errorMessage = Utility.GetExceptionMessageString(ex);
             return null;
         }
     }


     SortableCollection<CoreUser> IFileManagementService.GetCoreUsers(string sessionId, out string successMessage, out string errorMessage)
     {
         successMessage = string.Empty;
         errorMessage = string.Empty;
         try
         {
             // Update user session
             base.UpdateUserSession(sessionId);

             FileManager oFileManager = new FileManager();
             return oFileManager.GetCoreUsers(sessionId, out successMessage, out errorMessage);

         }
         catch (Exception ex)
         {
             Utility.LogEmail(ex);
             errorMessage = Utility.GetExceptionMessageString(ex);
             return null;
         }
     }


     void IFileManagementService.UploadFile(string sessionId, MyFile oMyFile, out string successMessage, out string errorMessage)
     {
         successMessage = string.Empty;
         errorMessage = string.Empty;
         try
         {
             // Update user session
             base.UpdateUserSession(sessionId);

             FileManager oFileManager = new FileManager();
             oFileManager.UploadFile(sessionId, oMyFile, out successMessage, out errorMessage);

         }
         catch (Exception ex)
         {
             Utility.LogEmail(ex);
             errorMessage = Utility.GetExceptionMessageString(ex);
             
         }
     }


     void IFileManagementService.DeleteFile(string sessionId, int fileId, out string successMessage, out string errorMessage)
     {
         successMessage = string.Empty;
         errorMessage = string.Empty;
         try
         {
             // Update user session
             base.UpdateUserSession(sessionId);

             FileManager oFileManager = new FileManager();
             oFileManager.DeleteFile(sessionId, fileId, out successMessage, out errorMessage);

         }
         catch (Exception ex)
         {
             Utility.LogEmail(ex);
             errorMessage = Utility.GetExceptionMessageString(ex);

         }
     }


        #endregion
    }

